package com.truthbean.jeetb.utils.web.invoker;

import com.truthbean.jeetb.utils.web.Utils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;

/**
 * Created by truth on 16-12-1.
 */
public class DeleteBatchInvoker extends DefaultInvoker {
    public boolean doBefore() {
        return false;
    }

    public boolean doAfter() {
        return false;
    }

    public void invoke(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws Exception {
        try {
            String files = request.getParameter("files");
            if (!Utils.isEmpty(files)) {
                String currentDir = session.getAttribute(CURRENT_DIR).toString();
                String[] arr = files.split(",");
                for (String fs : arr) {
                    File f = new File(currentDir, fs);
                    f.delete();
                }
            }
            session.setAttribute(MSG, "Delete Files Success!");
            //response.sendRedirect(SHELL_NAME + "?o=index");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
